package com.lc202309;

/**
 * Description:
 *
 * @Create 2023/9/25 22:53
 * @Version 1.0
 */
public class Solution2591 {
    public int distMoney(int money, int children) {
        // 钱小于孩子数
        if (money < children) {
            return -1;
        }
        // 钱大于8*孩子数
        if (money > children * 8) {
            return children - 1;
        }
        // 存在最后1个4元
        if (money == 8 * (children - 1) + 4) {
            return children - 2;
        }
        // 不存在4元情况
        int index = 0;
        while (money < 8 * (children - index) + index) {
            index++;
        }
        return children - index;
    }
}
